#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

const double zero = 1e-8;
const double pi = acos(-1);
const int maxn=300;

struct point{
	double x, y;
	point( double xx=0, double yy=0 ){
		x=xx; y=yy;
	}
	point operator -(point &t){
		point tmp( x-t.x, y-t.y );
		return tmp;
	}
	double angle(){
		double tmp = atan2( y, x );
		if ( tmp<-zero ) tmp+=2*pi;
		return tmp;
	}
	bool operator !=(point &t){
        if ( x!=t.x ) return true;
        if ( y!=t.y ) return true;
        return false;
	}
	double operator *(point &t){
        return (x*t.y-t.x*y);
    }       
};

int n;
point pp[maxn];
int ch[maxn], g[maxn][maxn];
int edge[maxn*maxn][2], tot;
bool use[maxn*maxn];
int nxt[maxn*maxn], limit, ans;
int app[maxn];

void init(){
	scanf("%d", &n);
	tot=0;
	for ( int i=0; i<n; i++ ){
		int p, x, y;
		scanf("%d %d %d", &p, &x, &y);
		scanf("%d", &ch[p]);
		pp[p].x=x; pp[p].y=y;
		for ( int j=0; j<ch[p]; j++ ){
			int t;
			scanf("%d", &t);
			tot++; edge[tot][0]=p; edge[tot][1]=t;
			g[p][j]=tot;
		}
	}
	scanf("%d", &limit);
}

void prepare(){
	for ( int i=1; i<=tot; i++ ){
		point a = pp[ edge[ i ][ 0 ] ]-pp[ edge[ i ][ 1 ] ];
		double ang = a.angle();
		int tt = edge[i][1];
		double min = 1e20;
		int wh;
		for ( int j=0; j<ch[tt]; j++ ){
			int p = g[tt][j];
			point tmp = pp[edge[p][1]]-pp[ tt ];
			double t = tmp.angle();
			double temp = t-ang;
			if ( temp<=zero ) temp+=2*pi;
			if ( min-temp>zero ){
				min = temp; wh = g[tt][j];
            }
		}
		nxt[i] = wh;
	}
}

void solve(){
	prepare();
	memset(use, 0, sizeof(use));
	memset(app, 0, sizeof(app));
	ans=0;
	for ( int i=1; i<=tot; i++ )
		if ( ! use[i] ){ 
			use[i]=true;
			point s = pp[edge[i][0]], t = pp[edge[i][1]];
			app[edge[i][1]]=i;
			bool ok=true;
			int sum=2;
			double area = 0;
			int wh = i;
			while (1){
				wh = nxt[ wh ];
				if ( wh==i ) break;
				use[wh]=true;
				point tt = pp[edge[wh][1]];
				if ( app[ edge[wh][1] ]==i )
				   ok=false;
				app[edge[wh][1]]=i; 
				sum++;
				point t1=t-s, t2=tt-s;
				area+=t1*t2;
				t=tt;
			}
			if ( --sum==limit && area<-zero && ok)
                ans++;
		}
	printf("%d\n", ans);
}

int main(){
	int test;
	scanf("%d", &test);
	while (test--){
		init();
		solve();
	}
}
